<?php
require_once("vcl/vcl.inc.php");
require_once("lib/db_connection.php");
//Includes
use_unit("components4phpfull/jtdivwindow.inc.php");
use_unit("components4phpfull/jtgroupbox.inc.php");
use_unit("components4phpfull/jtjavascript.inc.php");
use_unit("components4phpfull/jtiframe.inc.php");
use_unit("platinumgrid/jtplatinumgrid.inc.php");
use_unit("components4phpfull/jtsitetheme.inc.php");
use_unit("forms.inc.php");
use_unit("extctrls.inc.php");
use_unit("stdctrls.inc.php");

//Class definition
class Template_List2 extends Page
{
       public $Label2 = null;
       public $JTDivInfo = null;
       public $JTGroupBox1 = null;
       public $Label1 = null;
       public $imgInfo = null;
       public $imgBack = null;
       public $imgNext = null;
       public $JTJavaScript1 = null;
       public $Image3 = null;
       public $hiddenStyle = null;
       public $JTFrameRecurring = null;
       public $hiddenTemplateId = null;
       public $imageAddTemplate = null;
       public $hiddenId = null;
       public $JTTemplateList = null;
       public $JTSiteTheme1 = null;
       function Template_List2JSLoad($sender, $params)
       {

       ?>
       alert('Reminder for LTO Registration is automatically created upon enrollment of vehicle.');

       <?php

       }

       function imgInfoJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.getElementById('JTDivInfo').Show();
       <?php

       }

       function imgNextJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       window.location.href = "set_vehicle_list.php";
       <?php

       }

       function imgNextJSMouseOut($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['imgNext'].src = 'image/btn_next.png';
       <?php

       }

       function imgNextJSMouseOver($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['imgNext'].src = 'image/btn_next2.png';
       <?php

       }

       function imgBackJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       window.location.href = "set_vendor_list.php";
       <?php

       }

       function imgBackJSMouseOut($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['imgBack'].src = 'image/btn_back1.png';
       <?php

       }

       function imgBackJSMouseOver($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['imgBack'].src = 'image/btn_back21.png';
       <?php

       }

       function imageAddTemplateJSMouseOut($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images["imageAddTemplate"].src="image/add_new.png"
       <?php

       }

       function imageAddTemplateJSMouseOver($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images["imageAddTemplate"].src="image/add_new_blue.png"
       <?php

       }


       function Template_List2Create($sender, $params)
       {
       $temp_id = $_GET['template_id'];
       $style = $_GET['style'];
       $this->hiddenTemplateId->setValue($temp_id);
       $this->hiddenStyle->setValue($style);

       $query_template = mysql_query("select * from template_tbl where company_id='".$_SESSION['company_id']."'");
       $temp_list = mysql_num_rows($query_template);

       if($temp_list!=0)
       {
        if($temp_id==null || $temp_id=='')
        {
        $comp_id = $_SESSION['company_id'];
        $query_template = "select * from template_tbl where company_id='".$comp_id."' LIMIT 1";
        $result_template = mysql_query($query_template)or die(mysql_error());
        $row_template = mysql_fetch_array($result_template);
        $temp = $row_template['template_id'];

        $result_style = mysql_query("select * from template_tbl where template_id='".$temp."'")or die(mysql_error());
        $row_style = mysql_fetch_array($result_style);

        //die($query1);
        redirect('set_template_list.php?template_id='.$temp.'&style='.$row_style['style_id']);
        }
       }

       $this->imageAddTemplate->setLink('set_template_create.php');

       //$this->imgBack->setLink('vehicle_list.php?company='.$_SESSION['company_id']);
       $temp_id = $this->hiddenTemplateId->getValue();
       $style = $this->hiddenStyle->getValue();
       $this->JTFrameRecurring->setURL('template_recurring_list.php?template_id='.$temp_id.'&style='.$style);
       }

       function JTTemplateListShow($sender, $params)
       {
       $result_template = mysql_query("select * from template_tbl where company_id='".$_SESSION['company_id']."'")or die ('SELECT TEMPLATE'.mysql_error());
       $arr = array();
       while($row = mysql_fetch_array($result_template))
       {
       $template_id = $row['template_id'];
       $temp_type = $row['style_id'];

       if($this->hiddenTemplateId->getValue()==$template_id)
       $radio = "<a href=template_list.php?template_id=".$template_id."&style=".$temp_type."><img src='image/radio_select.png' border></a>";
       else
       $radio = "<a href=template_list.php?template_id=".$template_id."&style=".$temp_type."><img src='image/radio.png' border></a>";


       $template = "<a href=set_template_edit.php?template_id=".$template_id."&style=".$temp_type.">".$row['template_num']."</a>";
       $template_type = "<a href=set_template_edit.php?template_id=".$template_id."&style=".$temp_type.">".$row['template_type']."</a>";
       $tools = "<a href=set_template_recurring_list.php?template_id=".$template_id."&style=".$temp_type."><img src='image/check_reminder.png' title='reminder list' no border></a>
       <img onclick=js_deleteTemplate('".$template_id."'); src='image/delete.png' title='delete' style='cursor:pointer'>";
       //"<a href=template_delete.php?template_id=".$template_id."&style=".$temp_type."><img src='image/delete_orange.jpg' title='delete' no border></a>";
       $query_count = "SELECT count(id) AS count FROM template_recurring_tbl WHERE company_id='".$_SESSION['company_id']."' AND template_id='".$template_id."'";
       $result_count = mysql_query($query_count);
       $row_count = mysql_fetch_array($result_count);

       $count = $row_count['count'];

       $arr[] = array(
                        //'Template No.' => $template,
                        'Vehicle Type' => $template_type,
                        'No. of Reminders' => $count,
                        'Tools' => $tools
                        );
       }

        $this->JTTemplateList->setCellData($arr);

       }




}

global $application;

global $Template_List2;

//Creates the form
$Template_List2=new Template_List2($application);

//Read from resource file
$Template_List2->loadResource(__FILE__);

//Shows the form
$Template_List2->show();

?>